import vue from '@vitejs/plugin-vue';
import { defineConfig } from 'vite';
import { join, resolve } from 'path';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';

export default defineConfig(() => {
  return {
    plugins: [
      vue(),
      createSvgIconsPlugin({
        // 指定要缓存的图标文件夹
        iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
        // 指定symbolId格式
        symbolId: 'icon-[dir]-[name]',
      }),
    ],
    resolve: {
      alias: {
        '@': join(__dirname, './src'),
      },
    },
    // css的配置项
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss"; @import "./src/styles/slider.scss"; @import "./src/styles/navBar.scss";',
        },
      },
    },
    server: {
      proxy: {
        '/api': {
          // 获取数据的服务器地址
          target: 'http://sph-api.atguigu.cn',
          // 是否代理跨域
          changeOrigin: true,
          // 路径重写
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
  };
});
